﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelloWPF.DataBinding
{
    /// <summary>
    /// 对象的静态属性绑定
    /// </summary>
    public class StaticClass
    {
        public static event EventHandler<PropertyChangedEventArgs> ValueChanged;
        public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
        
        private static int _value = 555;

        public static int Value
        {
            get { return _value; }
            set
            {
                _value = value;
                //这种方式不可用（因为静态的PropertyChanged没有this）
                //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
                //第一种方式进行变化通知，与属性名称一一对应（属性名称 + Changed）
                ValueChanged?.Invoke(null, new PropertyChangedEventArgs("Value"));
                //第二种试进行变化通知 
                //StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs("Value"));
            }
        }

        public static event EventHandler<PropertyChangedEventArgs> Value2Changed;
        private static int _value2 = 666;

        public static int Value2
        {
            get { return _value2; }
            set
            {
                _value2 = value;
                //Value2Changed?.Invoke(null, new PropertyChangedEventArgs("Value2"));
                StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs("Value2"));
            }
        }
    }
}
